package org.blade.personal.controller;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.blade.personal.component.Const;
import org.blade.personal.manager.codeGen.PackageDefinedManager;
import org.blade.personal.mode.codegen.PackageDefined;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;

@Controller
@RequestMapping("/packageDefined/*")
public class PackageDefinedController {

	private  PackageDefinedManager packageDefinedManager;
	
	@RequestMapping("toPackageDefined")
	public ModelAndView toPackageDefined(){
		ModelAndView to = new ModelAndView("role-authority");
		to.addObject("title", "包管理");
		return to;
	}
	
	/**
	 * 抓取权限
	 * @param reqParam
	 * @return
	 */
	@ResponseBody
	@RequestMapping("fetch")
	public List fetch(@RequestParam Map reqParam){
		Long id = MapUtils.getLong(reqParam, "id");
		int usrOrRole = MapUtils.getIntValue(reqParam, "usrOrRole");
		return packageDefinedManager.getPackage();
		
		//以对应的节点找到对应的文件
	}
	
	/**
	 * 添加包
	 * @param reqParam
	 * @return
	 */
	@ResponseBody
	@RequestMapping("addPkg")
	public int addPackage(@RequestParam Map data){
		String json = MapUtils.getString(data, Const.Buesiness.DATA);
		PackageDefined pkg = JSON.parseObject(json, PackageDefined.class);
		packageDefinedManager.save(pkg);
		return 1;
	}
	
	/**
	 * 添加包
	 * @param reqParam
	 * @return
	 */
	@ResponseBody
	@RequestMapping("addPkg")
	public int updatePackage(@RequestParam Map data){
		String json = MapUtils.getString(data, Const.Buesiness.DATA);
		PackageDefined pkg = JSON.parseObject(json, PackageDefined.class);
		packageDefinedManager.update(pkg);
		return 1;
	}
	

}
